let button = document.querySelector('#button')
// let id = getQueryString('productid')
fetch('http://chst.vip:1234/api/getcoupon')
    .then(body => body.json())
    .then(res => {
        console.log(res)
        let el = ""
        res.result.forEach(item => {
            // let regExp = /(?<=imgurl=)[^'"]*/;
            // let url = item.couponImg.match(regExp);
            el += `<a couponid=${item.couponId}>
            <p couponid=${item.couponId}>
            <img src=${item.couponImg} couponid=${item.couponId}>
            <span couponid=${item.couponId}>${item.couponTitle}</span>
        </p></a>`
     
        })
        console.log(el)
        button.innerHTML=el;
       
    })
    button.onclick=  function(e){
        if(e.target.localName=='a' || e.target.localName=='p' || e.target.localName=='img' || e.target.localName=='span' ) {
            let _this = e.target
            let id = _this.getAttribute('couponid')
            location.href = './../pages/couponproduct.html?couponid=' + id;
        }
    }